package com.yaoming.umengshare;

import android.content.Context;
import android.content.Intent;

import com.umeng.socialize.bean.SHARE_MEDIA;
import com.yaoming.umengshare.listener.ShareResultListener;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zwj on 2015/12/25.
 */
public class UmShare implements Serializable{
    public static ShareResultListener mListener;
    public static Context mContext;
    private boolean defutPlatform = true;
    private List<SharePlatform> platformList;
    private int imageId=-1;
    private String title,text,targetUrl,videoUrl,videoThumb,imageUrl,musicUrl,musicThumb;
    public UmShare(Context context,ShareResultListener listener) {
        this.mContext = context;
        platformList = new ArrayList<>();
        this.mListener=listener;

    }
//    public void setPlatform(SHARE_MEDIA... medias) {
//        if (medias != null && medias.length != 0) {
//            defutPlatform = false;
//            SharePlatform bean;
//            for (SHARE_MEDIA media : medias) {
//                bean = new SharePlatform(media);
//                platformList.add(bean);
//            }
//        }
//    }

    public void setPlatform(SharePlatform... platfroms) {
        if (platfroms != null && platfroms.length != 0) {
            defutPlatform = false;
            SharePlatform bean;
            for (SharePlatform platfrom : platfroms) {

                platformList.add(platfrom);
            }
        }
    }
    private void initPlatform(){
        platformList.clear();
        platformList.add(new SharePlatform(SHARE_MEDIA.WEIXIN));
        platformList.add(new SharePlatform(SHARE_MEDIA.WEIXIN_CIRCLE));
        platformList.add(new SharePlatform(SHARE_MEDIA.QQ));
        platformList.add(new SharePlatform(SHARE_MEDIA.QZONE));
        platformList.add(new SharePlatform(SHARE_MEDIA.SINA));
        platformList.add(new SharePlatform(SHARE_MEDIA.TENCENT));
    }



    public void share() {
        if (defutPlatform){
            initPlatform();
        }
        Intent intent=new Intent(mContext,ShareActivity.class);
//        mListener=new ShareResultListener();



        intent.putExtra("umshare",(Serializable) this);
        intent.putExtra("platform_list",(Serializable) platformList);
        if (title!=null){
            intent.putExtra("title",title);
        }
        if (text!=null){
            intent.putExtra("text",text);
        }
        if (targetUrl!=null){
            intent.putExtra("targetUrl",targetUrl);
        }
        if(imageUrl!=null){
            intent.putExtra("imageUrl",imageUrl);
        }
        if (imageId!=-1){
            intent.putExtra("imageId",imageId);
        }
        if(videoUrl!=null){
            intent.putExtra("videoUrl",videoUrl);
        }
        if(musicUrl!=null){
            intent.putExtra("musicUrl",musicUrl);
        }
        if(musicThumb!=null){
            intent.putExtra("musicThumb",musicThumb);
        }
        if(videoThumb!=null){
            intent.putExtra("videoThumb",videoThumb);
        }
        mContext.startActivity(intent);
    }

    public void setMusicThumb(String musicThumb) {
        this.musicThumb = musicThumb;
    }
    public void setVideoThumb(String videoThumb) {
        this.videoThumb = videoThumb;
    }

    public void setTitle(String title){
        this.title=title;
    }
    public void setText(String text){
        this.text=text;
    }
    public void setTargetUrl(String url){
        this.targetUrl=url;
    }
    public void setImage(String url){
        this.imageUrl=url;
    }
    public void setImage(int id){
        this.imageId=id;
    }
    public void setVideo(String Url){
        this.videoUrl=Url;
    }
    public void setMusic(String Url){
        this.musicUrl=Url;
    }
    public void setMusic(String Url,String thumb){
        this.musicUrl=Url;
        this.musicThumb=thumb;
    }

}
